<?php

namespace backend\models;

use yii\helpers\ArrayHelper;
/**
 * This is the ActiveQuery class for [[ItemType]].
 *
 * @see ItemType
 */
class ItemTypeQuery extends \yii\db\ActiveQuery
{
    /*public function active()
    {
        $this->andWhere('[[status]]=1');
        return $this;
    }*/

    /**
     * @inheritdoc
     * @return ItemType[]|array
     */
    public function all($db = null)
    {
        return parent::all($db);
    }

    public function getAllData(){
        $models = ItemType::find()->all();
        $models = ArrayHelper::map($models,'id','name','pid');
        $result = [];
        foreach($models[0] as $key => $value){
            $result[$key] = $value;
            if(isset($models[$key])){
                foreach($models[$key] as $k => $v){
                    $result[$k] = '--------'.$v;
                }
            }
        }
        var_dump($result);
    }
    
    public function getAllParent(){
        $models = ItemType::find()->where(['pid'=>0])->all();
        $models = ArrayHelper::map($models,'id','name');
        array_unshift($models,'');
        return $models?$models:'';
    }
    
    public function getNameById($id){
        $model = ItemType::findOne($id);
        return $model?$model['name']:'';
    }
    
    /**
     * @inheritdoc
     * @return ItemType|array|null
     */
    public function one($db = null)
    {
        return parent::one($db);
    }
}